/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.交替合并字符串;

import java.util.LinkedList;

public class Main {
    public String mergeAlternately(String word1, String word2) {
        LinkedList<Character> data1=new LinkedList<>(),data2=new LinkedList<>();
        StringBuilder stringBuilder=new StringBuilder();
        for (char c : word1.toCharArray()) {
            data1.addLast(c);
        }
        for (char c : word2.toCharArray()) {
            data2.addLast(c);
        }
        while (!data1.isEmpty()||!data2.isEmpty()){
            if (!data1.isEmpty())
                stringBuilder.append(data1.pollFirst());
            if (!data2.isEmpty())
                stringBuilder.append(data2.pollFirst());
        }
        return stringBuilder.toString();
    }
}
